clear
set more off, perm
cd /Users/zachbrown/Projects/PriceTransparency/Data/

use Raw/ref_tables/REF_PAYER.dta, clear

keep payercode payercode_desc
decode payercode_desc, gen(payername_long)
drop payercode_desc

gen payername_short = ""
replace payername_short = "Aetna" if strpos(payername_long,"Aetna")>0
replace payername_short = "Anthem" if strpos(payername_long,"Anthem")>0
replace payername_short = "Cigna" if strpos(payername_long,"Cigna")>0
replace payername_short = "Cigna" if strpos(payername_long,"CIGNA")>0
replace payername_short = "Anthem" if strpos(payername_long,"Anthem")>0
replace payername_short = "Harvard Pilgrim" if strpos(payername_long,"Harvard Pilgrim")>0
replace payername_short = "UnitedHealth" if strpos(payername_long,"UnitedHealth")>0
replace payername_short = "UnitedHealth" if strpos(payername_long,"United Health")>0
replace payername_short = "Connecticut General" if strpos(payername_long,"Connecticut General")>0
replace payername_short = "Matthew Thornton" if strpos(payername_long,"Matthew Thornton")>0

replace payername_short = "Other" if payername_short==""

gen payer_on_web = 0
replace payer_on_web = 1 if inlist(payername_short,"Cigna","Harvard Pilgrim","Anthem")

encode payername_long, gen(payernm_long)
encode payername_short, gen(payernm_short)
drop payername_long payername_short

collapse (mean) payernm_long payernm_short payer_on_web, by(payercode) fast

label val payernm_long payernm_long
label val payernm_short payernm_short

duplicates report payercode

compress
save build/payers_clean.dta, replace





